' Test ad Simple Prime Sieve.txt rev from SB.exe 2018-09-14 adopted from:
' Simple sieve 2.bas SmallBASIC 2015-04-29 found a faster sieve with BASIC 256
topN = 1000
limit = topN ^ .5
. Primes to ;topN
' take care of even numbers first
' prime the pump
[
	+= i,1
	Jmp i > topN
	Set composites, i, 0
]
i = 4
[
	Set composites, i, 2
	+= i,2
	Jmp i > topN
]
' now do odd numbers
i = 3
[
	Get test, composites, i
	If test = 0
		If i < limit
			j = 2 * i
			[
				Set composites, j, i
				+= j,i
				Jmp j > topN
			]
		Fi
	Fi
	i = i + 2
	Jmp i > limit 
]
i = 2
pCount = 0
[
	Get test, composites, i
	If test = 0 
		+= pCount,1
		, i
		        ' the next line has caused an error with what looked like extra space at end of line 
				' if cnt did not match fi count but I can't repeat the error? the next line is fine.
	            Fi           
	+= i,1
	Jmp i > topN
]
. 
.
. / There are ;pCount;/ primes for the first ; topN;/ integers.
